package com.tank.game.api.config;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 缺省的配置项
 *
 * @author Zed
 */
public class DefaultParamsConfig implements Parameters, Serializable {


    private static final long serialVersionUID = 865169500040287608L;
    private final Map<String, String> params;

    /**
     * 构造方法
     *
     * @param builder
     */
    public DefaultParamsConfig(ParamsBuilder builder) {
        this.params = builder.params == null ?
                Collections.emptyMap() :
                Collections.unmodifiableMap(builder.params);
    }

    @Override
    public String getParameter(String name) {
        return this.params.get(name);
    }

    @Override
    public List<String> getParameterNames() {
        return new ArrayList<>(this.params.keySet());
    }

    @Override
    public List<String> getParameterNames(String prefix) {
        return this.params.keySet().stream()
                .filter(name -> name.startsWith(prefix))
                .collect(Collectors.toList());
    }
}
